<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;
class Test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command test';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
    	DB::table('goods')->delete();
		$file = fopen("goods.csv","r");
		
		
		$n=0;
		while (!feof($file)) {
			$str = fgetcsv($file);
			DB::table('goods')->insert([
				'shop_code'			=> (string)$str[0],
				'bar_code'			=> (string)$str[1],
				'goods_name'		=> mb_convert_encoding($str[2], "UTF-8", "GBK"),
				'goods_guige'		=> mb_convert_encoding($str[3], "UTF-8", "GBK"),
				'goods_unit'		=> mb_convert_encoding($str[4], "UTF-8", "GBK"),
				'mall_price'		=> $str[5],
				'goods_cate'		=> mb_convert_encoding($str[6], "UTF-8", "GBK"),
				'supplier'			=> mb_convert_encoding($str[7], "UTF-8", "GBK"),
				'updated_at'=>date("Y-m-d H:i:s"),
				'created_at' =>date("Y-m-d H:i:s"),
				]);
				echo $n++.'.';
				
			
		}
	

		fclose($file);
		$this->line('ok');
        
    }
}
